package com.lisa.passjava.search.controller;

import com.lisa.common.es.QuestionEsModel;
import com.lisa.common.exception.BizCodeEnum;
import com.lisa.common.utils.R;
import com.lisa.passjava.search.service.IElasticSearchQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RequestMapping("/search")
@RestController
public class ElasticSearchQuestionController {

    @Autowired
    private IElasticSearchQuestionService questionService;
    // 保存题目到 ES。
    @RequestMapping("/question/save")
    public R saveQuestion(@RequestBody QuestionEsModel questionEsModel){
        boolean result = true;
        try{
            result = questionService.save(questionEsModel);
        }catch (Exception e){
            log.error("ElasticSearchQuestionController保存题目到ES错误：{}" ,e);
            return R.error(BizCodeEnum.QUESTION_SAVE_EXCEPTION.getCode(),BizCodeEnum.QUESTION_SAVE_EXCEPTION.getMsg());
            //result =false;
        }
        if(result){
            return R.ok();
        }else{
            return R.error(BizCodeEnum.QUESTION_SAVE_EXCEPTION.getCode(),BizCodeEnum.QUESTION_SAVE_EXCEPTION.getMsg());
        }

    }
}
